package com.jeeplus.modules.statistics.service;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jeeplus.database.datasource.annotation.DS;
import com.jeeplus.modules.statistics.mapper.EmployeeMapper;
import com.jeeplus.modules.statistics.model.Employee.EmployeeEntity;
import com.jeeplus.modules.statistics.util.PageBean;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;


@DS("queuing")
@Service
@RequiredArgsConstructor
@Slf4j
@Transactional
public class EmployeeService {

   private final EmployeeMapper employeeMapper;


    public int addEmployee(EmployeeEntity employeeEntity) {
        int i = employeeMapper.addEmployee(employeeEntity);
        return i;
    }


    public int delEmployee(String id) {
        int i = employeeMapper.delEmployee(id);
        return i;
    }


    public int updateEmployee(EmployeeEntity employeeEntity) {
        int i = employeeMapper.updateEmployee(employeeEntity);
        return i;
    }


    public PageBean<EmployeeEntity> findEmployee(Map<String, Object> map) {
        PageBean<EmployeeEntity> pageBean=new PageBean<>();
        PageHelper.startPage(Integer.parseInt(map.get("curPage")+""), Integer.parseInt(map.get("pageSize")+""));

        List<EmployeeEntity> list=employeeMapper.findEmployee(map);
        PageInfo<EmployeeEntity> pageInfo=new PageInfo<>(list);
        pageBean.setCrurentNum(Integer.parseInt(map.get("curPage")+""));
        pageBean.setPageSize(Integer.parseInt(map.get("pageSize")+""));
        pageBean.setTotalNum((int) pageInfo.getTotal());
        pageBean.setTotalPageSize(pageInfo.getPages());
        pageBean.setDatas(pageInfo.getList());
        return pageBean;
    }

    public EmployeeEntity findEmployeeById(String id) {
        EmployeeEntity employeeById = employeeMapper.findEmployeeById(id);
        System.out.println(employeeById);
        return employeeById;
    }


    public List<Map<String, Object>> findRegion() {
        List<Map<String, Object>> region = employeeMapper.findRegion();
        return region;
    }
    /**
     * 查询全部员工
     * @return 员工对象的集合
     */
    public List<EmployeeEntity> findEmployeeAll(){
        List<EmployeeEntity> all = employeeMapper.findEmployeeAll();
        return all;
    }
}
